package com.itheima.map;

import java.util.Comparator;
import java.util.TreeMap;

public class Demo4 {
    public static void main(String[] args) {
        TreeMap<Student,String> t = new TreeMap<>((o1, o2) -> {
            int result = o1.getAge() - o2.getAge();
            result = result == 0 ? o1.getName().compareTo(o2.getName()) : result;
            return result;
        });
        Student s1 = new Student("xiaohei",23);
        Student s2 = new Student("dapang",22);
        Student s3 = new Student("xiaomei",22);
        t.put(s1,"江苏");
        t.put(s2,"上海");
        t.put(s3,"北京");

        t.forEach((k,v)->{
            System.out.println(k+"-->"+v);
        });
    }
}
class Student {
    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
